package vrp;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import java.io.IOException;
import javax.jdo.PersistenceManager;
import javax.servlet.http.*;

import vrp.PMF;
import vrp.WHProvider;

public class WHProviderDeleteServlet extends HttpServlet {

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
    	
    	PersistenceManager pm = PMF.get().getPersistenceManager();
    	
        long keyid = Integer.parseInt(req.getParameter("key"));
        
        Key key = KeyFactory.createKey(WHProvider.class.getSimpleName(), keyid);
        WHProvider whProvider = pm.getObjectById(WHProvider.class, key);

        //check certain cases when cannot delete the whProvider
        
        
        try {
            pm.deletePersistent(whProvider);
        } finally {
            pm.close();
        }
        resp.sendRedirect("/whProviders.jsp");
    }
}
